package cn.example.vip.mall.goods.service.impl;

import cn.example.vip.mall.goods.entity.Category;
import cn.example.vip.mall.goods.mapper.CategoryMapper;
import cn.example.vip.mall.goods.service.CategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
	@Autowired
	CategoryMapper categoryMapper;
	
	/**
	 * 根据 parentId 查询
	 * @param parentId
	 * @return
	 */
	@Override
	public List<Category> findByParentId(Integer parentId){
		QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("parent_id",parentId);
		return categoryMapper.selectList(queryWrapper);
	}
	
	/**
	 * 条件查询
	 * @param category
	 * @return
	 */
	@Override
	public List<Category> queryList(Category category) {
		QueryWrapper<Category> wrapper = new QueryWrapper<>();
		wrapper.like(category.getName() != null, "name", category.getName());
		return categoryMapper.selectList(wrapper);
	}
	
	/**
	 * 分页查询
	 * @param category
	 * @param page
	 * @param size
	 * @return
	 */
	@Override
	public Page<Category> queryPageList(Category category, Long page, Long size) {
		QueryWrapper<Category> wrapper = new QueryWrapper<>();
		wrapper.like(category.getName() != null, "name", category.getName());
		return categoryMapper.selectPage(new Page<>(page, size), wrapper);
	}
}
